package br.domsd.pocketcontrol.action;

import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.util.Log;
import android.view.View;
import br.domsd.pocketcontrol.MainActivity;
import br.domsd.pocketcontrol.R;
import br.domsd.pocketcontrol.model.MonthExpenses;
import br.domsd.pocketcontrol.model.Period;

public class MainActivityActionListener implements OnClickListener, android.view.View.OnClickListener
{

	private XMLHandler xmlHandler;
	private MainActivity mainActivity;
	
	public MainActivityActionListener(MainActivity paramMainActivity)
	{
		mainActivity = paramMainActivity;
		xmlHandler = new XMLHandler(mainActivity.getApplicationContext());
	}
	
	public void onClick(View v) 
	{
		
		if(v.getId() == R.id.btnCreateXML)
		{
			Log.d(MainActivityActionListener.class.getSimpleName(), "Button Clicked: Create XML");
			String month = mainActivity.getSelectedMonth();
			String year = mainActivity.getSelectedYear();
			
			Period period = new Period(month, year);
			
			xmlHandler.createXML(period);
			
			Log.d(MainActivityActionListener.class.getSimpleName(),"Creating XML for: " + mainActivity.getSelectedMonth() + "/" + mainActivity.getSelectedYear());

			mainActivity.updateMonthExpensesListView();
		}
		
		if(v.getId() == R.id.btnReadXML)
		{
			Log.d(MainActivityActionListener.class.getSimpleName(), "Button Clicked: Read XML");
			String month = mainActivity.getSelectedMonth();
			String year = mainActivity.getSelectedYear();
			
			Period period = new Period(month, year);
			
			xmlHandler.readXML(period);
			
			Log.d(MainActivityActionListener.class.getSimpleName(), "Reading XML for: " + mainActivity.getSelectedMonth() + "/" + mainActivity.getSelectedYear());
			
		}
	}

	public void onClick(DialogInterface dialog, int which) 
	{
		// TODO Auto-generated method stub
		
	}

}
